package com.com.knowledgepaymentmanagementsystem.service.user.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.com.knowledgepaymentmanagementsystem.mapper.user.AdminMapper;
import com.com.knowledgepaymentmanagementsystem.pojo.user.Admin;
import com.com.knowledgepaymentmanagementsystem.pojo.login.LoginBean;
import com.com.knowledgepaymentmanagementsystem.service.user.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @author 张攀
 * @version 1.0
 * @description: TODO
 * @date 2025/9/24 下午4:35
 */
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public HashMap<String, Object> login(LoginBean loginBean) {
        //精确提示信息
        String msg = "";
        //1.创建map集合
        HashMap<String, Object> map = new HashMap<>();

        //2.根据用户输入的账号查询：账号从loginBean参数中查询
        QueryWrapper<Admin> query = new QueryWrapper<>();
        query.eq("account",loginBean.getAccount());
        Admin admin = adminMapper.selectOne(query); //text 来自数据库的用户数据
        //3.判断 admin
        if(null == admin){
            msg = "账号不存在";
        }
        else {
//            4.验证账号状态是否可以正常登录
            if(admin.getAdminState() == 1){
                //正常，验证密码
                //4.验证密码
                if(loginBean.getPassword().equals(admin.getPassword())){
                    msg = "登录成功";
                    //存储用户信息
                    map.put("admin",admin);
                }
                else {
                    msg = "密码错误";
                }
            }else {
                //账号被禁用
                msg="账号已被禁用，联系管理员";
            }

        }
        //存储到map集合中
        map.put("msg",msg);
        return map;
    }
}
